package com.wans.ssq.controller.v1;

import com.wans.common.result.ResponseResult;
import com.wans.model.lottery.ssq.dos.SSQ;
import com.wans.model.lottery.ssq.dtos.SSQHistoryDTO;
import com.wans.ssq.common.util.SSQHistoryDTOValidationUtils;
import com.wans.ssq.mapper.SSQMapper;
import com.wans.ssq.service.SSQService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/lottery/ssq/history")
public class SSQHistoryController {

    @Autowired
    @Qualifier("SSQHistoryServiceImpl")
    private SSQService ssqHistory;
    @Autowired
    private SSQMapper ssqMapper;

    // 获取数据库中最新的期次
    @GetMapping("/getNew")
    public ResponseResult<SSQ> getNewHistoryCode() {
        return ssqHistory.getNewHistoryCode();
    }

    // 插入数据库中最新的期次
    @PostMapping("/saveNew")
    public ResponseResult<Integer> saveNewHistoryCode(@RequestBody SSQ ssq) {
        return ssqHistory.saveNewHistoryCode(ssq);
    }

    // 获取数据库中指定的期次的数据
    @GetMapping("/getCode")
    ResponseResult<SSQ> getSSQHistoryByCode(@RequestParam("code") String code) {
        return ResponseResult.success(ssqMapper.getHistoryByCode(code));
    }

    // 获取期次列表
    @GetMapping("/list")
    public ResponseResult<List<SSQ>> listHistory(SSQHistoryDTO ssqHistoryDTO) {

        // 校验
        SSQHistoryDTOValidationUtils.validate(ssqHistoryDTO);

        return ssqHistory.listHistory(ssqHistoryDTO);
    }
}
